package edu.gdkm.collection;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

//Map 映射， key-value 键值对
public class MapDemo {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("0001","张三");
        map.put("0002","李四");
        map.put("0002","王五");

        Iterator it1 = map.keySet().iterator();
        while(it1.hasNext()){
            System.out.println(it1.next());
        }
        Iterator it2 = map.values().iterator();
        while(it2.hasNext()){
            System.out.println(it2.next());
        }
        System.out.println("学号为0002的同学是："+map.get("0002"));   //直接通过key的值获取value信息
        System.out.println("移除0002的同学前:"+map);
        map.remove("0002");                //移除某个key-value
        System.out.println("移除0002的同学后:"+map);
    }
}
